<template>
  <a-card :bordered="false">
    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">
          <a-col :md="4" :sm="6">
            <a-form-item label="计划编号">
              <a-input placeholder="请输入" v-model="queryParam.planNo"></a-input>
            </a-form-item>
          </a-col>
          <a-col :md="4" :sm="6">
            <a-form-item label="计划名称">
              <a-input placeholder="请输入" v-model="queryParam.planName"></a-input>
            </a-form-item>
          </a-col>
          <a-col :md="4" :sm="6">
            <a-form-item label="计划年度">
              <a-date-picker
                :mode="mode"
                placeholder="请选择年份"
                format="YYYY"
                :allowClear="false"
                value-format="yyyy-MM-dd"
                v-model="queryParam.year"
                :open="yearPickShow"
                style="width: 100%"
                @panelChange="handlePanelChange"
                @openChange="handleOpenChange"
              />
            </a-form-item>
          </a-col>
          <a-col :md="4" :sm="6">
            <a-form-item label="计划类型">
              <j-dict-select-tag
                style="width: 100%"
                v-model="queryParam.planType"
                placeholder="请选择"
                dict-code="inconplantype"
              />
            </a-form-item>
          </a-col>

          <a-col :md="6" :sm="8">
            <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
            <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">清除条件</a-button>
          </a-col>
        </a-row>
      </a-form>
    </div>

    <a-table
      ref="table"
      size="middle"
      bordered
      rowKey="id"
      :columns="columns"
      :dataSource="dataSource"
      :pagination="ipagination"
      :loading="loading"
      @change="handleTableChange"
    >
      <span slot="actionName">
        <a-button size="small" @click="openCreatModel()" type="primary" icon="plus">新增</a-button>
      </span>
      <span slot="status" slot-scope="text,record">
        <span v-if="text != '3'">{{ status[text] }}</span>
        <a v-else @click="handleLookAudit(record,'审批详情')">{{ status[text] }}(查看原因)</a>
      </span>

      <span slot="fileNameList" slot-scope="text, record">
        <!-- <span v-if="!record.fileNameList">无</span> -->
        <a @click="handleLookFile(record)">查看</a>
      </span>
      <span slot="action" slot-scope="text, record">
        <a @click="handleDetail(record, '内部评价计划-详情')">查看</a>
        <template v-if="record.isEdit === '1'">
          <a-divider type="vertical" />
          <a @click="handleEdit(record, '内部评价计划-编辑')">编辑</a>
        </template>
      </span>
    </a-table>
    <!-- table区域-end -->

    <create-plan ref="modalForm" @openModelView="handleAddSubmit"></create-plan>
    <FileModel ref="fileModel"></FileModel>
    <CheckAndEditModel ref="auditView"></CheckAndEditModel>
  </a-card>
</template>

<script>
import { JeecgListMixin } from '@/mixins/JeecgListMixin'
import columns from './indexColumns'
import createPlan from './createPlan'
import FileModel from './components/FileModel.vue'
import { httpAction, getAction, postAction, deleteAction } from '@/api/manage'
import moment from 'moment'
import CheckAndEditModel from './CheckAndEditModel.vue'

export default {
  name: 'jh',
  mixins: [JeecgListMixin],
  components: {
    createPlan,
    FileModel,
    CheckAndEditModel,
  },
  data() {
    return {
      // 表头
      columns: columns(this),
      ipagination: {
        current: 1,
        pageSize: 10,
        pageSizeOptions: ['10', '20', '30'],
        showTotal: (total, range) => {
          return range[0] + '-' + range[1] + ' 共' + total + '条'
        },
        showQuickJumper: true,
        showSizeChanger: true,
        total: 0,
      },
      status: {
        0: '待提交',
        1: '待审核',
        2: '已通过',
        3: '已驳回',
      },
      mode: 'year',
      url: {
        list: '/incon/inconReviewPlan/queryPlan',
        add: '/incon/inconReviewPlan/createPlan',
        file: '/incon/inconReviewPlan/queryFileList',
      },
      yearPickShow: false,
    }
  },
  computed: {},
  methods: {
    openCreatModel() {
      this.$refs.modalForm.title = '新增'
      this.$refs.modalForm.disableSubmit = false
      this.$refs.modalForm.visible = true
    },
    handleLookAudit(record,name) {
      this.$refs.auditView.check(record)
      this.$refs.auditView.title = name
      // this.$refs.modalForm.disableSubmit = true
    },
    handleAddSubmit(evt) {
      return new Promise((re, rj) => {
        postAction(this.url.add, evt).then((res) => {
          if (res.success) {
            this.loadData()
            this.$refs.modalForm.visible = false
            // this.$refs.modalForm.queryParam = {
            //   planType: '03',
            //   year: '',
            //   month: '',
            //   date: '',
            // }
            this.$refs.modalForm.queryParam = {
              date: '',
              month: '',
              quarter: '',
              year: '',
            }
            this.$refs.modalForm.quarterShow = false
            this.$refs.modalForm.yearShow = true
            this.$refs.modalForm.monthShow = false
            this.$message.success(res.message)
            re(res.success)
          } else {
            rj(res.success)
            this.$message.error(res.message)
          }
        })
      })
    },
    handlePanelChange(value) {
      this.queryParam.year = moment(value).format('YYYY')
      this.yearPickShow = false
      this.$refs.form.validateField('year', (error) => {
        console.log(error)
      })
    },
    // 弹出日历和关闭日历的回调
    handleOpenChange(status) {
      this.yearPickShow = status
    },
    // TODO 查看附件
    handleLookFile(record) {
      // this.getFileList(record)
      // this.$refs.fileModel.visible = true
      // this.fileModel.title = '查看'
      this.$refs.fileModel.look(record, 'yearPlan')
    },
  },
}
</script>
<style scoped>
@import '~@assets/less/common.less';
</style>